import store from "@/store/index.js"

// 文件上传
export function uploadFile({path, size}, callback, progress) {
    let uploadTask = uni.uploadFile({
        url:  `${store.state.vuex_baseUrl}/common/upload`,
        header: {
            Authorization: `Bearer ${store.state.vuex_token}`,
        },
        name: 'file',
        filePath: path,
        formData: {
            size
        },
        complete: (res) => {
            if(res.statusCode != 200) return;
            callback(JSON.parse(res.data));
        }
    });
    if(progress && typeof progress === "function") uploadTask.onProgressUpdate(progress);
}